#!/bin/bash
# 启动nginx
# 分别在三台设备启动日志服务器

nginx_home=/opt/module/nginx
app_home=/opt/module/gmall210422
jar=gmall-logger-0.0.1-SNAPSHOT.jar

case $1 in
"start")

if [[ -z "`pgrep -f nginx`" ]]; then
    echo "在hadoop162 启动nginx "
    $nginx_home/sbin/nginx
else
    echo "nginx在hadoop162已经启动,无序重复启动"

fi
for host in hadoop162 hadoop163 hadoop164 ; do
    echo "在 $host 启动日志服务器 "
    ssh $host "nohup java -jar $app_home/$jar 1>$app_home/gmall.log 2>&1 &"
done

   ;;
"stop")
echo "在hadoop162 停止nginx "
$nginx_home/sbin/nginx -s stop

for host in hadoop162 hadoop163 hadoop164 ; do
    echo "在 $host 停止日志服务器 "
    ssh $host "jps | awk '/$jar/ {print \$1}'|xargs kill -9"
done

;;
*)
    echo "你启动姿势不对: "
    echo " 启动日志采集: log.sh start "
    echo " 停止日志采集: log.sh stop "
;;
esac



